<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title> 书籍管理 </title>
  <link rel="stylesheet" type="text/css" href="/css/style.css" />

  <style type="text/css">
    *, body {
      margin: 0px;
      font-family: '微软雅黑';
    }
  </style>
  <script src="~/js/jquery-1.10.2.min.js"></script>
  <script src="~/js/generic.js"></script>
  <script src="~/js/fypage.js"></script>
</head>

<body>
@Html.Partial("top")

<table class="maintable"style="width:100%">
  <tr>
    @Html.Partial("menu")
    <td class="rightmaintd" valign="top">
      <div style="height:40px;text-align:center;background-color:#009966">
        <p style="font-weight:bold;padding-top:10px;font-size:larger;color:white">书籍管理</p>
      </div>
      <div class="searchdiv">
        <input type="button" value="+添加书籍" class="denglubtn" onclick="createAdmin();">
        <input type="button" value="+批量添加" class="denglubtn" onclick="BatchAdd();">
        <div class="rightsearchdiv"><!-- name --><div class="rightsearchdivtext"><input type="text" id="keyword" class="nobodertext" placeholder="查询书籍"> <button class="searchbtn" onclick="search();"><img src="/images/fdj.png" alt="" class="searchfdj"></button>  </div> </div>
      </div>
      <table class="neirontbiao" id="tbl_list"style="width:100%"></table>

      <div class="pagediv" id="pager">
      </div>

    </td>
  </tr>
</table>

@Html.Partial("bottom")

</body>
</html>
<script type="text/javascript">
  var submit = false;
  var pager;
  $(document).ready(function () {
    pager = new Fypager("pager", getList);
    getList();
  });
  function createAdmin() {
    location.href = "/Book/edit";
  }
  function BatchAdd() {
    location.href = "/Book/batchAdd";
  }
  function updateAdmin(Bookid) {
    location.href = "/Book/edit/" + Bookid;
  }
  function deleteAdmin(Bookid) {
    if (confirm("确认删除当前书籍吗")) {
      util.post("/Book/delete", { "id": Bookid }, function (json) {
        if (json.status == 0) {
          getList();
        } else {
          alert(json.msg);
        }
      });
    }
  }

  function search() {
    pager.goPage(1);
  }

  function getList() {
    var url = "/Book/GetList?pageIndex=" + pager.currPage + "&pageSize=" + pager.pageNum;
    util.getJSON(url, { "keyword": $("#keyword").val() }, function (json) {
      if (json.status == 0) {
        pager.showPager(json.totalPage, json.totalNum, json.pageCount);
        showList(json.list);
      } else {
        alert(json.msg);
      }
    });
  }

  function showList(list) {
    var html = '<tr class="neirontbiaotou"><td width="15%">书名</td><td width="10%">作者</td><td width="15%">出版社</td><td width="10%">版次</td><td width="15%">出版时间</td><td width="19%">ISBN</td><td width="10%"></td></tr>';
    if (list.length == 0) {
      html += '<tr><td colspan="7" style="text-align:center;height:50px;">暂无书籍</td></tr>';
    }
    for (var i = 0; i < list.length; i++) {
      html += '<tr>';
      html += '<td title="' + list[i].id + '">' + util.formateTitle(list[i].name, 10, true) + '</td>';
      html += '<td title="' + list[i].name + '">' + util.formateTitle(list[i].author, 10, true) + '</td>';
      html += '<td title="' + list[i].type + '">' + util.formateTitle(list[i].publisher, 10, true) + '</td>';
      html += '<td>' + util.FormateNull(list[i].edition) + '</td>';
      html += '<td>' + util.FormateNull(list[i].editionTime) + '</td>';
      html += '<td>' + util.FormateNull(list[i].isbn) + '</td>';
      html += '<td>' + '<a href="javascript:updateAdmin(\'' + list[i].id + '\')">编辑</a>&nbsp;<a href="javascript:deleteAdmin(\'' + list[i].id + '\')">删除</a>' + '</td></tr>';
    }
    $("#tbl_list").html(html);
  }
</script>
